

public class CornerOrientationTable extends mainS{
	public int[][] cOrientTable = new int[8][2186];

	String convert(String ternInitPos, int index, int cycle){
		Character a = ternInitPos.charAt(index);
		String c = a.toString();
		int intA = Integer.parseInt(c);
	
		String first = ternInitPos.substring(0, index);
		String second = ternInitPos.substring(index+1);
		String mid = Integer.toString(cOrientCycle(intA, cycle));
		return first + mid + second;
		
	}
	public String getTernary(int decimal){
		String result = "";
		for (int i = 7; i >= 0; i--){
			int trit;
			int sub = decimal - (int) Math.pow(3, i);
			if (sub > 0){
				sub = sub - (int) Math.pow(3, i);
				if (sub > 0) trit = 2;
				else trit = 1;
				decimal -= Math.pow(3, i);
			}
			else trit = 0;
			
			String tritString = Integer.toString(trit);
			result += tritString;
			
		}
		
		return result;
	}
	public int getDecimal(String ternary){
		int result = 0;
		int pow = 0;
		for (int i = ternary.length()-1; i > -1; i--){
			result += Integer.parseInt(Character.toString(ternary.charAt(i))) * ((int) (Math.pow(3, pow))); //because fuck you, that's why
			pow ++;
		}
		
		
		return result;
	}
	
	int getCOResult(int turn, int initPos){
//		UFL : 0 -> 1; 1 -> 2; 2 -> 0; is case 0
//		UFR : 0 -> 2; 1 -> 0; 2 -> 1; is case 1
		
		String ternInitPos = getTernary(initPos);
		switch (turn){ //'??
		case 0:
			ternInitPos = convert(ternInitPos, 2, 0);
			ternInitPos = convert(ternInitPos, 3, 1);
			ternInitPos = convert(ternInitPos, 6, 0);
			ternInitPos = convert(ternInitPos, 7, 1);
			break;
		case 1:
			ternInitPos = convert(ternInitPos, 3, 0);
			ternInitPos = convert(ternInitPos, 7, 1);
			ternInitPos = convert(ternInitPos, 5, 0);
			ternInitPos = convert(ternInitPos, 1, 1);
			break;
		case 2:
			ternInitPos = convert(ternInitPos, 0, 0);
			ternInitPos = convert(ternInitPos, 1, 1);
			ternInitPos = convert(ternInitPos, 5, 0);
			ternInitPos = convert(ternInitPos, 4, 1);
			break;
		case 3:
			ternInitPos = convert(ternInitPos, 2, 0);
			ternInitPos = convert(ternInitPos, 6, 1);
			ternInitPos = convert(ternInitPos, 4, 0);
			ternInitPos = convert(ternInitPos, 0, 1);
			break;
		}
		return getDecimal(ternInitPos);
		
	}
	
	int posit = 0;
	int genCornerOrientationTable(){
		for (int i = 0; i < 8; i++){
			for (int j = 0; j < 2186; j++){
				cOrientTable[i][j] = getCOResult(i,j);
			}
			
		}
		return 0;
	}
	public CornerOrientationTable(){
		
	}
	
}
